package com.example.fragmenttest.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.example.fragmenttest.Bean.User;
import com.example.fragmenttest.R;

import java.util.List;

public class UserAdapter extends ArrayAdapter<User> {
    int resourceid ;
    //加入构造方法
    public UserAdapter(@NonNull Context context, int resource, @NonNull List<User> objects) {
        super(context, resource, objects);
        resourceid=resource ;
    }
    @Override
    public View getView(int positon, View converView , ViewGroup parent) {
        View view = converView;
        if (view == null) {
            view = LayoutInflater.from(getContext()).inflate(resourceid, null);
        }
        TextView uidtxt = view.findViewById(R.id.uidtxt);
        TextView usntxt=view.findViewById(R.id.usntxt);
        TextView permissiontxt=view.findViewById(R.id.permissiontxt) ;
        User user =getItem(positon);
        uidtxt.setText("id: "+user.getId());
        usntxt.setText("名字： "+user.getName());
        //1.第一种方法  显示用户或者管理员
//        if(user.getPermission()==1){
//
//            permissiontxt.setText("权限：用户");
//        }else {
//            permissiontxt.setText("权限：管理员");
//        }

        /*
        *方法2   把permission 当做下标
        * */
        String [] a={"","用户","管理员"};
        permissiontxt.setText("权限: "+a[user.getPermission()]);

        return  view ;

//        permissiontxt.setText("权限:"+user.getPermission());
    }

}
